package com.xy.iot.netty.channel;

import com.xy.iot.common.message.BaseMessage;
import com.xy.iot.netty.service.NameValueImpl;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;

import java.net.InetSocketAddress;
@Slf4j
public class BaseContextChannel extends NameValueImpl implements BaseChannel {

	private final ChannelHandlerContext ctx;
	private final InetSocketAddress address;

	public BaseContextChannel(ChannelHandlerContext ctx) {
		this.ctx = ctx;
		this.address = (InetSocketAddress) this.ctx.channel().remoteAddress();
		name(address.getHostString());
	}

	@Override
	public void send(BaseMessage msg) {
		sendData(this.ctx.channel(),msg);
	}

	public InetSocketAddress remoteAddress() {
		return (InetSocketAddress) this.ctx.channel().remoteAddress();
	}
}
